import { provide, reactive } from 'vue'
import { Session } from '/@/utils/storage'
import type { Store } from '../types'

export const useStore = () => {
  const csdevCodeFormData = Session.get('csdevCodeFormData')

  const store = reactive<Store>({
    codeConfig: {},
    apis: {},
    loading: false,
    basicFormRef: undefined,
    basicFormData: csdevCodeFormData?.basicConfig || {
      modulePath: '',
      apiFilePath: ''
    },
    apiFormRef: undefined,
    apiFormData: csdevCodeFormData?.apiConfig || {
      listPage: ''
    },
    listPageFormRef: undefined,
    listPageFormData: csdevCodeFormData?.listPageConfig || {
      rowKey: ''
    }
  })
  provide('CSDEV_CODE_VIEW_STORE', store)
  return store
}
